#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define maxVexNums 10
typedef struct Enode
{
    int adjVex;
    struct Enode *next;
}Enode;
typedef struct Vnode
{
    Enode *firstEdge;
    char data;
}Vnode,adjList[maxVexNums];
typedef struct Graph
{
    adjList vertices;
    int numV,numE;
}mg;

void create_mg(mg *g){
    int i,j;
    printf("请输入顶点个数i和边的条数j:");
    scanf("%d%d",&g->numV,&g->numE);
    printf("请输入顶点信息:");
    for(int k=0;k<g->numV;k++){
        getchar();
        scanf("%c",&g->vertices[k].data);
        g->vertices[k].firstEdge=NULL;
    }
    printf("输入vi,vj所对应的i,j:");
    for(int k=0;k<g->numE;k++){
        scanf("%d%d",&i,&j);
        Enode *edge=(Enode*)malloc(sizeof(struct Enode));
        edge->adjVex=j;
        edge->next=g->vertices[i].firstEdge;
        g->vertices[i].firstEdge=edge;//头插法
    }
} 
void reverse(mg A,mg *B){
    B->numE=A.numE;
    B->numV=A.numV;
    for(int i=0;i<A.numV;i++){
        B->vertices[i].data=A.vertices[i].data;
        B->vertices[i].firstEdge=NULL;
    }
    Enode *pa,*pb;
    for(int i=0;i<B->numV;i++){
        pa=A.vertices[i].firstEdge;
        while(pa!=NULL){
            int k=pa->adjVex;//pa边此时所指向的顶点序号
            pb=(Enode*)malloc(sizeof(struct Enode));
            pb->adjVex=i;//构造一个指向i的边节点
            pb->next=B->vertices[k].firstEdge;
            B->vertices[k].firstEdge=pb;//用头插法把构造的边结点挂到此时pa指向顶点序号的adjList中
            pa=pa->next;
        }
    }
}
void printMG(mg g){
    for(int i=0;i<g.numV;i++){
        printf("%c->",g.vertices[i].data);
        Enode *node=g.vertices[i].firstEdge;
        int count=0;
        while(node){
            printf("%c->",g.vertices[node->adjVex].data);
            node=node->next;
            count++;
        }
        printf(" 此顶点入度%d\n",count);
    }
    
}
int main(){
    mg g;
    create_mg(&g);
    // printMG(g);
    mg B;
    reverse(g,&B);
    printMG(B);
    return 0;
}